package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

import org.come.bean.Role_bean;
import org.come.until.*;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.RoleCaoZuoBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



public class AddFriendJpanel extends JPanel {

    private RoleCaoZuoBtn labId,// ID查找
            labName;// 名字查找
    private JTextField field; // 输入查询条件框
    private RoleCaoZuoBtn zuoBtn,// 加为好友按钮
            zuoBtn2,// 搜索按钮
            zuoBtn3;// 申请入队按钮
    private JScrollPane jScrollPane; // 查询出来的玩家列表滚动条
    // 玩家信息表格
    private JTable tableMsg;
    // 玩家信息表格中的对象
    private DefaultTableModel tableModel;
    private Vector<Vector<String>> verVectors;// 玩家信息的集合
    private Vector<String> verStrings;// 放置玩家信息的集合
    private String tj = "数字ID";

    private Role_bean role;// 选中的好友信息

    public void CF(Role_bean role_bean) {
        verVectors.clear();
        verStrings.clear();
        this.role = role_bean;
        if (role != null) {
            verStrings.add(0, role.getRolename());
            verStrings.add(1, AnalysisString.lvl(role.getGrade().intValue()));
            verStrings.add(2, role.getRace_name());
            verStrings.add(3, "不愿透露");
            verVectors.add(0, verStrings);
        }
    }

    public AddFriendJpanel() {
        this.setPreferredSize(new Dimension(402, 359));
        this.setLayout(null);
        this.setBackground(UIUtils.Color_BACK);

        // 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 75);
        offBtn.setBounds(402 - 37, 10, 25, 25);
        this.add(offBtn);

        tableModel = new DefaultTableModel();

        verVectors = new Vector<Vector<String>>();
        verStrings = new Vector<String>();
        verVectors.add(verStrings);
        tableModel.setDataVector(verVectors, Util.vector2);
        tableMsg = new JTable() {
            {
                setOpaque(false);
            } // instance initializer

            @Override
            public boolean isCellEditable(int row, int column) {
                // TODO Auto-generated method stub
                return false;
            }
        };

        // 帮派成员信息表格
        tableMsg.setShowGrid(false);

        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
        renderer.setHorizontalAlignment(SwingConstants.CENTER);
        tableMsg.setDefaultRenderer(Object.class, renderer);

        JTableHeader header = tableMsg.getTableHeader();

        // 设置表头的高度
        header.setPreferredSize(new Dimension(header.getWidth(), 0));
        tableMsg.getTableHeader().setBackground(new Color(0, 0, 0, 0));
        tableMsg.getTableHeader().setVisible(true);
        tableMsg.getTableHeader().setBorder(BorderFactory.createLineBorder(Color.ORANGE));

        tableMsg.setSelectionBackground(new Color(0, 0, 0, 0));
        tableMsg.setSelectionForeground(Color.red);
        tableMsg.setForeground(Color.yellow);
        tableMsg.setFont(new Font("微软雅黑", 1, 13));
        tableMsg.setBackground(UIUtils.Color_BACK);
        tableMsg.setModel(tableModel);

        // 设置列间距
        tableMsg.getColumnModel().getColumn(0).setPreferredWidth(100);
        tableMsg.getColumnModel().getColumn(1).setPreferredWidth(70);
        tableMsg.getColumnModel().getColumn(2).setPreferredWidth(60);
        tableMsg.getColumnModel().getColumn(3).setPreferredWidth(60);
        tableMsg.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        tableMsg.isCellEditable(1, 1);
        tableMsg.setEnabled(true);

        // 查询出来的玩家列表滚动条
        jScrollPane = new JScrollPane();
        jScrollPane.setViewportView(tableMsg);
        jScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
        jScrollPane.getViewport().setOpaque(false);
        jScrollPane.setOpaque(false);
        jScrollPane.setBounds(49, 123, 311, 158);
        jScrollPane.setBorder(BorderFactory.createEmptyBorder());
        jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        this.add(jScrollPane);

        // 输入查询条件框
        field = new JTextField();
        field.setBounds(121, 70, 97, 16);
        field.setBackground(UIUtils.Color_BACK);
        field.setBorder(BorderFactory.createEmptyBorder());
        field.setFont(UIUtils.TEXT_FONT1);
        field.setCaretColor(Color.white);
        field.setForeground(Color.white);
        this.add(field);

        // UIUtils.COLOR_BTNPUTONG
        // UIUtils.COLOR_BTNTEXT
        // 搜索按钮
        zuoBtn2 = new RoleCaoZuoBtn("skin/8100226/newbutton/B30.png", 1, "搜索", 7, UIUtils.COLOR_BTNTEXT);
        zuoBtn2.setBounds(218, 70, 34, 17);
        this.add(zuoBtn2);
        // 加为好友按钮
        zuoBtn = new RoleCaoZuoBtn("skin/8100226/newbutton/B22.png", 1, "加为好友", 6, UIUtils.COLOR_BLACK);
        zuoBtn.setBounds(83, 292, 99, 24);
        this.add(zuoBtn);
        // 申请入队按钮
        zuoBtn3 = new RoleCaoZuoBtn("skin/8100226/newbutton/B22.png", 1, "申请入队", 6, UIUtils.COLOR_BLACK);
        zuoBtn3.setBounds(245, 292, 99, 24);
        this.add(zuoBtn3);

        labId = new RoleCaoZuoBtn("skin/8100226/button/B242.png", 1, 11, this);
        labId.setBounds(56, 25, 100, 35);
        this.add(labId);

        labName = new RoleCaoZuoBtn("skin/8100226/button/B245.png", 1, 12, this);
        labName.setBounds(158, 25, 100, 35);
        this.add(labName);
    }

    /**
     * 点击菜单
     */
    public void labMenuChange(int type) {
        if (type == 11) {
            try {
                labId.setIcons(CutButtonImage.cuts("skin/8100226/button/B242.png"));
                labName.setIcons(CutButtonImage.cuts("skin/8100226/button/B245.png"));
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            tj = "数字ID";
            field.setText("");
            CF(null);
        } else if (type == 12) {
            try {
                labId.setIcons(CutButtonImage.cuts("skin/8100226/button/B244.png"));
                labName.setIcons(CutButtonImage.cuts("skin/8100226/button/B243.png"));
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            tj = "昵称";
            field.setText("");
            CF(null);
        }
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // 好友列表
        if (icon == null) {
            icon = new ImageIcon("inkImg/newbackground/B309.png");
        }
        g.drawImage(icon.getImage(), 0, 0, 402, 359, this);
        g.setColor(UIUtils.COLOR_NAME16);
        g.setFont(UIUtils.TEXT_FONT21);
        g.drawString(tj, 50, 85);

    }

    public Role_bean getRole() {
        return role;
    }

    public void setRole(Role_bean role) {
        this.role = role;
    }

    /**
     * 获取输入的内容
     */
    public String getFieldText() {
        return field.getText();
    }

    public String getTj() {
        return tj;
    }
}
